﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClipperBaseUI.Controls;

namespace Clipper.ClipperWindow
{
    /// <summary>
    /// WinShowMessage.xaml 的交互逻辑
    /// </summary>
    public partial class WinShowMessage : BaseWindow
    {
        public enum MsgBoxBtns
        {
            OK,
            OKCancel,
            YesNo,
            YesNoCancel,
            RetryCancel,
            AbortRetryCancel
        }
        public enum DlgResult
        {
            Yes,
            No,
            OK,
            Cancel,
            Retry,
            Abort,
            Ignore
        }

        public enum MsgBoxIcon
        {
            Information,
            Exclamation,
            Question,
            Error,
            Warning
        }

        private DlgResult mResult = DlgResult.OK;
        private MsgBoxBtns mButtons;
        private MsgBoxIcon mIcon;

        public WinShowMessage()
        {
            InitializeComponent();
        }

        private void mPicBtn1_Click(object sender, RoutedEventArgs e)
        {
            switch (this.mButtons)
            {
                case MsgBoxBtns.OK:
                case MsgBoxBtns.OKCancel:
                    this.mResult = DlgResult.OK;
                    break;

                case MsgBoxBtns.YesNo:
                case MsgBoxBtns.YesNoCancel:
                    this.mResult = DlgResult.Yes;
                    break;

                case MsgBoxBtns.RetryCancel:
                    this.mResult = DlgResult.Retry;
                    break;

                case MsgBoxBtns.AbortRetryCancel:
                    this.mResult = DlgResult.Abort;
                    break;
            }
            base.Close();
        }

        private void mPicBtn2_Click(object sender, RoutedEventArgs e)
        {
            switch (this.mButtons)
            {
                case MsgBoxBtns.OKCancel:
                case MsgBoxBtns.RetryCancel:
                    this.mResult = DlgResult.Cancel;
                    break;

                case MsgBoxBtns.YesNo:
                case MsgBoxBtns.YesNoCancel:
                    this.mResult = DlgResult.No;
                    break;

                case MsgBoxBtns.AbortRetryCancel:
                    this.mResult = DlgResult.Retry;
                    break;
            }
            base.Close();
        }

        private void mPicBtn3_Click(object sender, RoutedEventArgs e)
        {
            switch (this.mButtons)
            {
                case MsgBoxBtns.YesNoCancel:
                case MsgBoxBtns.AbortRetryCancel:
                    this.mResult = DlgResult.Cancel;
                    break;
            }
            base.Close();
        }
        public static DlgResult ShowDlg(string content, string title, MsgBoxBtns btns, MsgBoxIcon icon)
        {
            WinShowMessage box = new WinShowMessage();
            box.Title = title;
            box.mlblContent.Text = content;
            box.mButtons = btns;
            //{
            //    mlblTitle = { Text = title },
            //    mlblContent = { Text = content },
            //    mButtons = btns
            //};
            int y = 0xa6;
            switch (box.mButtons)
            {
                case MsgBoxBtns.OK:
                    box.mPicBtn1.Margin = new Thickness(165, 123, 0, 0);
                    box.mPicBtn2.Visibility = Visibility.Hidden;
                    box.mPicBtn3.Visibility = Visibility.Hidden;
                    box.mPicBtn1.Content = "确定";
                   // box.mPicBtn1.Refresh();
                    break;

                case MsgBoxBtns.OKCancel:
                    box.mPicBtn1.Margin = new Thickness(80, 123, 0, 0);
                    box.mPicBtn2.Margin = new Thickness(250, 123, 0, 0);
                    box.mPicBtn3.Visibility = Visibility.Hidden;
                    box.mPicBtn1.Content = "确定";
                    box.mPicBtn2.Content = "取消";
                    //box.mPicBtn1.Refresh();
                    //box.mPicBtn2.Refresh();
                    break;

                case MsgBoxBtns.YesNo:
                    box.mPicBtn1.Margin = new Thickness(80, 123, 0, 0);
                    box.mPicBtn2.Margin = new Thickness(250, 123, 0, 0);
                    box.mPicBtn3.Visibility = Visibility.Hidden;
                    box.mPicBtn1.Content = "是";
                    box.mPicBtn2.Content = "否";
                    //box.mPicBtn1.Refresh();
                    //box.mPicBtn2.Refresh();
                    break;

                case MsgBoxBtns.YesNoCancel:
                    box.mPicBtn1.Margin = new Thickness(55, 123, 0, 0);
                    box.mPicBtn2.Margin = new Thickness(165, 123, 0, 0);
                    box.mPicBtn3.Margin = new Thickness(278, 123, 0, 0);
                    box.mPicBtn1.Content = "是";
                    box.mPicBtn2.Content = "否";
                    box.mPicBtn3.Content = "取消";
                    //box.mPicBtn1.Refresh();
                    //box.mPicBtn2.Refresh();
                    //box.mPicBtn3.Refresh();
                    break;

                case MsgBoxBtns.RetryCancel:
                    box.mPicBtn1.Margin = new Thickness(80, 123, 0, 0);
                    box.mPicBtn2.Margin = new Thickness(250, 123, 0, 0);
                    box.mPicBtn3.Visibility = Visibility.Hidden;
                    box.mPicBtn1.Content = "重试";
                    box.mPicBtn2.Content = "取消";
                    //box.mPicBtn1.Refresh();
                    //box.mPicBtn2.Refresh();
                    break;

                case MsgBoxBtns.AbortRetryCancel:
                    box.mPicBtn1.Margin = new Thickness(55, 123, 0, 0);
                    box.mPicBtn2.Margin = new Thickness(165, 123, 0, 0);
                    box.mPicBtn3.Margin = new Thickness(278, 123, 0, 0);
                    box.mPicBtn1.Content = "忽略";
                    box.mPicBtn2.Content = "重试";
                    box.mPicBtn3.Content = "取消";
                    break;
            }
            box.mIcon = icon;
            ResourceDictionary style1;
            style1 = new ResourceDictionary();
            switch (box.mIcon)
            {
                case MsgBoxIcon.Information:

                    style1.Source = new Uri(@"Resources\information.png", UriKind.Relative);
                    box.picIcon.Resources = style1;
                    break;

                case MsgBoxIcon.Question:
 
                    style1.Source = new Uri(@"Resources\question", UriKind.Relative);
                    box.picIcon.Resources = style1;
                    break;

                case MsgBoxIcon.Error:

                    style1.Source = new Uri(@"Resources\error", UriKind.Relative);
                    box.picIcon.Resources = style1;
                    break;

                case MsgBoxIcon.Warning:
            
                    style1.Source = new Uri(@"Resources\warning", UriKind.Relative);
                    box.picIcon.Resources = style1;
                    break;
            }
            //box.TopMost = true;
            box.ShowDialog();
            return box.mResult;
        }
    }
}

